package com.sikaryofficial.backend.config;

import cn.hutool.core.text.CharSequenceUtil;
import com.sikaryofficial.backend.domain.vo.CountryAgeLimitVO;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * @author : qinjinyuan
 * @desc : 政策年龄配置
 * @date : 2023/10/31 16:51
 */
@Configuration
@RefreshScope
@ConfigurationProperties(prefix = "hismk.country-age")
@Getter
@Setter
public class CountryAgeLimitConfig {
    private final static Integer defaultAge = 21;
    private List<CountryAgeLimitVO> configList;

    public Integer getAgeByCode(String isoCountryCode) {
        return configList.stream().filter(item -> CharSequenceUtil.equals(item.getIsoCountryCode(), isoCountryCode)).findFirst()
                .orElse(new CountryAgeLimitVO("", defaultAge, "")).getAge();
    }
}
